/*!***************************************************
 * @file: login.h
 * @brief: 登陆模块头文件
 * @author: ITHAO 
 * @date: 2018.12.6
 * @note: 
 ****************************************************/
#ifndef __LOGIN_APP_H__
#define __LOGIN_APP_H__

#include <stdbool.h>
/*这里不能直接包含app.h，因为app.h也要包含当前头文件，
如果直接包含app.h会发生头文件嵌套包含的情况，
本文件定义的结构体就会在app.h定义不到*/
struct mutexfd;

typedef unsigned char   uint8;
typedef unsigned short  uint16;
typedef unsigned int    uint32;

#define FAIL    0
#ifndef TRUE
#define TRUE    1
#endif

enum login_ret {
    LOGIN_NAME_WRONG_FROMAT = 2,
    LOGIN_ACCOUNT_WRONG_FROMAT,
    LOGIN_PASSWORD_WRONG_FROMAT,
    LOGIN_SHORT_OF_DATA,
    LOGIN_ACCOUNT_EXIST,
    LOGIN_ACCOUNT_NOT_EXIXT,
    LOGIN_PASSWORD_INCORRECT,
    LOGIN_TOO_MUCH,
    LOGIN_ACCOUNT_HAS_BEEN_LOGIN,
    LOGIN_NOT_ONLINE,
};

enum login_err {
    LOGIN_INFO_EMPTY_ERR = 1,
    LOGIN_PARAM_NULL_ERR,
    LOGIN_FD_INVALID_ERR,
    LOGIN_SEND_ERR,
    LOGIN_RECV_ERR,
};

#define NAME_LENGTH        (11)
#define ACCOUNT_LENGTH     (11)
#define PASSWORD_LENGTH    (11)
struct login_info {
    char name[NAME_LENGTH]; 
    char account[ACCOUNT_LENGTH];
    char password[PASSWORD_LENGTH];
};


extern void login_info_init(struct login_info *p_login_info);
extern int user_register(struct login_info login_info, struct mutexfd *mutexfd);
extern int user_login(struct login_info *p_login_info, struct mutexfd *mutexfd);
extern int user_logout(struct mutexfd *mutexfd);
extern bool is_user_online(char *account, struct mutexfd *mutexfd);


#endif